package com.domi.bean;

import lombok.Data;

@Data
public class RestfulResponse {

    private String code;

    private String mesg;

    private Object data;

    public static RestfulResponse create(ResponseCode responseCode) {
        RestfulResponse response = new RestfulResponse();
        response.code = responseCode.code;
        response.mesg = responseCode.mesg;
        return response;
    }

    public static RestfulResponse create(ResponseCode responseCode, String mesg) {
        RestfulResponse response = new RestfulResponse();
        response.code = responseCode.code;
        response.mesg = mesg;
        return response;
    }

    public static RestfulResponse create(ResponseCode responseCode, String mesg, Object data) {
        RestfulResponse response = new RestfulResponse();
        response.code = responseCode.code;
        response.mesg = mesg;
        response.data = data;
        return response;
    }

    public static RestfulResponse create(ResponseCode responseCode, Object data) {
        RestfulResponse response = create(responseCode);
        response.data = data;
        return response;
    }

    public static enum ResponseCode {

        FAIL("100", "业务处理失败"),

        ERROR("700", "发生异常"),

        SUCCESS("200", "业务处理完成");

        private String code;

        private String mesg;

        private ResponseCode(String code, String mesg) {
            this.code = code;
            this.mesg = mesg;
        }

    }

}